/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pap.pickapartner;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Horario implements Comparable{

    private char horario;   //A,B,C,D,E,F...
    private Date data;  // dd/mm/yyyy
    private int recorrente; //3, 2, 1 semanas
    
    
    public Horario(char horario, int dia, int mes, int recorrente) throws ParseException{
        this.horario = horario;
         String dat = ((dia > 9)? ("" + dia) : ("0" + dia)) + "/";
         dat+= ((mes > 9)? ("" + mes) : ("0" + mes)) + "/" + year();
         DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
         this.data = df.parse(dat);
         this.data.setTime(this.data.getTime()+25800000 + (horario-'A')*50*60*1000);
         this.recorrente = recorrente;
    }
    
    public boolean recorrer(){
        if(recorrente>0){
            data.setTime(data.getTime()+((24L*3600L*1000L)*7L));
            recorrente--;
            return true;
        }
        
        return false;
    }

    public Date getData() {
        return data;
    }

    public void setData(Date data) {
        this.data = data;
    }

    public char getHorario() {
        return horario;
    }

    public void setHorario(char horario) {
        this.horario = horario;
    }

    public int getRecorrente() {
        return recorrente;
    }

    public void setRecorrente(int recorrente) {
        this.recorrente = recorrente;
    }
    
    @Override
    public boolean equals(Object obj){
        char hor = ((Horario)obj).getHorario();
        Date dat = ((Horario)obj).getData();
        if((this.horario==hor) && this.data.equals(dat))
            return true;
        return false;
    }
    
    @Override
    public String toString(){
        DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT);
        String horario1 = format.format(data);
        horario1 += " " + this.horario;
        return horario1;
    }
    
    public int compareTo(Object objeto){
        int value = this.data.compareTo(((Horario)objeto).getData());
        if(value>0){
            return 1;}
        else{
            if(value<0){
                return -1;
            }else{
                char hora = ((Horario)objeto).getHorario();
                return (this.getHorario() - hora);
            }
        }
               
    }
    
    private int year() {
       Date data1 = new Date();
       long ano = 1970 + (data1.getTime() / (365L*24L*3600L*1000L + 4L*3600L*1000L));
       return ((int)ano);
   }
    
   public void sayHello(){
       System.out.println("OI");
   }


  
    
   public static void main(String[] args){
        
        Horario hor;
        try {
            hor = new Horario('G', 21, 6, 2);
            //hor.recorrer();
            System.out.println(hor.toString());
            Horario h = new Horario('H', 21, 6, 2);
            System.out.println(h.toString());
            System.out.println(hor.compareTo(hor));
            int i1= 10;
            int i2 = 20;
            System.out.println((Integer.valueOf(i1)).compareTo(Integer.valueOf(i1)));
     
            System.out.println((7*3600*1000)+(10*60*1000));
            
            //System.out.println(hor);
            hor.sayHello();
        } catch (ParseException ex) {
            Logger.getLogger(Horario.class.getName()).log(Level.SEVERE, null, ex);
        }
      
    }
    
    
    
}
